package ultweb.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.servlet.ModelAndView;



import java.util.Map;
import java.util.HashMap;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import ultweb.service.ProductManager;

@Controller
@SessionAttributes
public class InventoryController {

    protected final Log logger = LogFactory.getLog(getClass());
    private String me="InventoryController-";
    
    @Autowired
    private ProductManager productManager;
  
    @RequestMapping(value = "/hello", method = RequestMethod.GET)
    public ModelAndView handleRequest(){
    	String foo=me +"handleRequest- ";
    	logger.info(foo+"begin ");
    	
        String now = (new java.util.Date()).toString();
        logger.info(foo+"returning hello view with " + now);

        Map<String, Object> myModel = new HashMap<String, Object>();
        myModel.put("now", now);
        myModel.put("prodotti", this.productManager.getProdotti());
        
        
        logger.info(foo+"End "+myModel);
    	return new ModelAndView("hello", "model", myModel);
    	
    }
    

}